//
//  DDropDurationTextLayer.swift
//  Drop
//
//  Created by hushaohua on 2018/9/24.
//  Copyright © 2018年 init. All rights reserved.
//

import UIKit

class DDropDurationTextLayer: CATextLayer {
    
    var stringSize:CGSize?;

    override func draw(in ctx: CGContext) {
        super.draw(in: ctx);
        if (self.stringSize != nil){
            let offsetX = (self.bounds.size.width - self.stringSize!.width) / 2;
            
            ctx.setLineWidth(1/UIScreen.main.scale);
            ctx.setStrokeColor(UIColor.lightGray.cgColor);
            ctx.setLineDash(phase: 0, lengths: [2,2]);
            ctx.move(to: CGPoint(x:0,y:self.bounds.size.height / 2));
            ctx.addLine(to: CGPoint(x:offsetX, y:self.bounds.size.height / 2));
            ctx.closePath();
            ctx.strokePath();
            
            ctx.move(to: CGPoint(x:offsetX + self.stringSize!.width,y:self.bounds.size.height / 2));
            ctx.addLine(to: CGPoint(x:self.bounds.size.width, y:self.bounds.size.height / 2));
            ctx.closePath();
            ctx.strokePath();
        }
    }
    
}
